import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 保养类型信息 */
export interface UpkeepCategory {
  id: number // 主键
  status?: number // 启用状态
  code: string // 编码
  name?: string // 名称
  accountMethod?: number // 核算方式
  upkeepPeriod?: number // 保养周期
  reminderPeriod?: number // 提醒周期
  description: string // 备注
}

/** 保养类型与保养项关联信息 */
export interface UpkeepCategory2Item {
  id?: number // 主键
  categoryId: number // 保养类型ID
  categoryName?: string // 保养类型名称
  itemId: number // 保养项ID
  itemName?: string // 保养项名称
}

// 保养类型 API
export const UpkeepCategoryApi = {
  // 批量创建保养类型与保养项的关联
  batchCreateUpkeepCat2item: async (data: UpkeepCategory2Item[]) => {
    return await request.post({ url: `/mold/upkeep-cat2item/update-catid`, data })
  },

  // 删除指定保养类型的关联项
  deleteByCategoryId: async (catId: number) => {
    return await request.delete({
      url: `/mold/upkeep-cat2item/delete-catid?catId=` + catId
    })
  },

  // 查询已绑定保养类型项目
  getItemsByCatId: async (catId: number) => {
    return await request.get({ url: `/mold/upkeep-cat2item/list-catid?catId=` + catId })
  },

  // 查询所有保养类型
  getUpkeepCategoryAll: async () => {
    return await request.get({ url: `/mold/upkeep-category/all` })
  },

  // 查询保养类型分页
  getUpkeepCategoryPage: async (params: any) => {
    return await request.get({ url: `/mold/upkeep-category/page`, params })
  },

  // 查询保养类型详情
  getUpkeepCategory: async (id: number) => {
    return await request.get({ url: `/mold/upkeep-category/get?id=` + id })
  },

  // 新增保养类型
  createUpkeepCategory: async (data: UpkeepCategory) => {
    return await request.post({ url: `/mold/upkeep-category/create`, data })
  },

  // 修改保养类型
  updateUpkeepCategory: async (data: UpkeepCategory) => {
    return await request.put({ url: `/mold/upkeep-category/update`, data })
  },

  // 删除保养类型
  deleteUpkeepCategory: async (id: number) => {
    return await request.delete({ url: `/mold/upkeep-category/delete?id=` + id })
  },

  /** 批量删除保养类型 */
  deleteUpkeepCategoryList: async (ids: number[]) => {
    return await request.delete({ url: `/mold/upkeep-category/delete-list?ids=${ids.join(',')}` })
  },

  // 导出保养类型 Excel
  exportUpkeepCategory: async (params) => {
    return await request.download({ url: `/mold/upkeep-category/export-excel`, params })
  },

  // 下载导入模板
  importTemplate: async () => {
    return request.download({ url: '/mold/upkeep-category/get-import-template' })
  }
}
